package com.example.asus.widget1;

import android.app.ListActivity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class ListViewActivity extends AppCompatActivity {
    private  String[] weekStrings={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

    Button buttonGrid;
    Button buttonRecycler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);

        buttonGrid=(Button) findViewById(R.id.buttonGrid);
        buttonRecycler=(Button) findViewById(R.id.buttonRecycler);

        buttonGrid.setOnClickListener(new buttonGrid());
        buttonRecycler.setOnClickListener(new buttonRecycler());

        ArrayAdapter<String> adapter=new ArrayAdapter<String>(ListViewActivity.this,android.R.layout.simple_list_item_1,weekStrings);

        ListView listView=(ListView)findViewById(R.id.listview);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ListViewActivity.this.setTitle(((TextView)view).getText());
            }
        });
    }

    class buttonGrid implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Intent intent=new Intent();
            intent.setClass(ListViewActivity.this,GridViewActivity.class);
            startActivity(intent);
        }
    }
    class buttonRecycler implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Intent intent=new Intent();
            intent.setClass(ListViewActivity.this,RecyclerViewActivity.class);
            startActivity(intent);
        }
    }
}
